package org.huntaway.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.io.IOUtils;

/**
 * Hello world!
 * 
 */
public class URLExample {
	public static void main(String[] args) {
		InputStream in = null;
		try {
			in = new URL("http://dict.cn").openStream();
			System.out.println(IOUtils.toString(in));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			IOUtils.closeQuietly(in);
		}
	}

	public void testCommon() throws MalformedURLException, IOException {
		InputStream in = new URL("http://laoyu.info").openStream();
		try {

			InputStreamReader inR = new InputStreamReader(in);
			BufferedReader buf = new BufferedReader(inR);
			String line;
			while ((line = buf.readLine()) != null) {
				System.out.println(line);
			}
		} finally {
			in.close();
		}
	}

	public void testCommonsIO() throws MalformedURLException, IOException {
		InputStream in = new URL("http://laoyu.info").openStream();
		try {
			System.out.println(IOUtils.toString(in));
		} finally {
			IOUtils.closeQuietly(in);
		}
	}

}
